import vavava.workshop
import vavava.workqueue
from vavava.fetcherpro import Fetcher

class www(vavava.workqueue.Work):
    def __init__(self,log,item):
        vavava.workqueue.Work.__init__(self,log=log)
        self.item = item

    def do(self,worker):
        self.log.info("???????????"+self.item)
        fetch_format=r'http://auspost.com.au/track/track.html?id=%s'
        self.log.debug("test:%s"%self.item)
        f = Fetcher(self.log)
        f.filters.append([1,"ISO-8859-1",fetch_format%self.item])
        f.filters.append([2,r'Please enter the above characters without any spaces'])
        f.exec()
        if len(f.datas) > 0:
            self.log.info("!!!!!!!!!!!"+self.item)


if __name__ == "__main__":
    import vavava.util
    log = vavava.util.initlog("./log/test.log")

    fetcher=Fetcher()
    fetcher.filters.append([ 1,'ISO-8859-1',"http://fastrackexpress.com.au/test.php?LIST=POST" ])
    fetcher.filters.append([2,r'<td>(?P<id>[^<]*)</td>'])
    fetcher.filters.append([3,0,1])
    fetcher.exec()

    ws = vavava.workshop.WorkShop(minsize=20,log=log)
    ws.StartWork()

    for item in fetcher.datas:
        work = www(log,item.values)
        ws.QueueWork(work)

    while True:
        import time
        time.sleep(1)


